package Util;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import eu.boss.R;
import eu.boss.model.ShadowColor;

public class Util {

	/**
	 * Testing Internet connexion
	 * 
	 * @param c Context where we want to test internet connexion
	 * 
	 * @return true if a connexion is available, else false.
	 */
	
	public static boolean isOnline(Context c) {

		Boolean connected = true;
		ConnectivityManager cm = (ConnectivityManager) c
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = cm.getActiveNetworkInfo();
		connected = networkInfo != null && networkInfo.isAvailable()
				&& networkInfo.isConnected();
		return connected;
	}
	
	/**
	 * Corresponding table to convert enum into drawable color
	 */
	public static Drawable getDrawableColor(Context c, ShadowColor shadowColor)
	{
		switch (shadowColor)
		{
		case BLACK:
			return c.getResources().getDrawable(R.drawable.rounded_black);
		case WHITE:
			return c.getResources().getDrawable(R.drawable.rounded_white);
		case ORANGE:
			return c.getResources().getDrawable(R.drawable.rounded_orange);
		case BLUE:
			return c.getResources().getDrawable(R.drawable.rounded_blue);
		case YELLOW:
			return c.getResources().getDrawable(R.drawable.rounded_yellow);
		case GREEN:
			return c.getResources().getDrawable(R.drawable.rounded_green);
		case RED:
			return c.getResources().getDrawable(R.drawable.rounded_red);
		case SAND:
			return c.getResources().getDrawable(R.drawable.rounded_sand);
		case PINK:
			return c.getResources().getDrawable(R.drawable.rounded_pink);
		case PURPLE:
			return c.getResources().getDrawable(R.drawable.rounded_purple);
		case GRAY:
			return c.getResources().getDrawable(R.drawable.rounded_gray);
		default:
			return null;
		}
		
	}
}